# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=python-sphinx-autoapi
_name=${pkgname#python-}
pkgver=3.0.0
pkgrel=1
pkgdesc="A new approach to API documentation in Sphinx."
arch=(any)
url="https://github.com/readthedocs/sphinx-autoapi"
license=(MIT)
depends=(
  python-anyascii
  python-astroid
  python-jinja
  python-sphinx
  python-yaml
)
makedepends=(git python-build python-installer python-setuptools python-wheel)
checkdepends=(python-beautifulsoup4 python-pytest)
source=("git+$url.git#tag=v$pkgver")
b2sums=('SKIP')

build() {
  cd "$_name"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "$_name"
  PYTHONPATH="$PWD/autoapi:$PYTHONPATH" pytest -v
}

package() {
  cd "$_name"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGELOG,README}.rst -t "${pkgdir}/usr/share/doc/${pkgname}"

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/sphinx_autoapi-$pkgver.dist-info/LICENSE.rst "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.rst
}
